package com.wenjie.terminal.config;

import android.app.Application;
import android.content.Context;
import android.hardware.usb.UsbDevice;

import com.pantum.lld.DeviceManager;
import com.wenjie.terminal.util.ConfigurationUtil;

import java.util.List;

import lombok.Getter;
import lombok.Setter;

/**
 * 应用信息
 * 用来保存应用运行期间的各种状态和实例
 */
@Getter
public class App extends Application {

    private Context context;

    /**
     * 打印机实例
     */
    @Setter
    private DeviceManager printDevice;

    /**
     * 所有的USB设备
     */
    @Setter
    private List<UsbDevice> usbDeviceList;

    /**
     * 配置文件设置或读取工具
     */
    private ConfigurationUtil configurationUtil;

    /**
     * 打印机信息是否已配置
     */
    @Setter
    private boolean isConfigPrinter = false;

    @Override
    public void onCreate() {
        super.onCreate();

        context = this.getApplicationContext();

        // 初始化配置文件工具类
        this.configurationUtil = ConfigurationUtil.getInstance(context);
    }

    @Override
    public void onTerminate() {
        if (printDevice != null) {
            printDevice.exit();
        }

        super.onTerminate();
    }
}
